package itheima05;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author xxx
 * @date 2020/12/23 22:08
 * @description
 */
public class Test  {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        //建立一个对象，通过数组将对象序列化和反序列化
            xlh();
            fxlh();
    }
      public  static  void  xlh() throws IOException {
          ObjectOutputStream objectOutputStream=new ObjectOutputStream(new FileOutputStream("day12\\listTest.txt"));
          Person person=new Person("11",20);
          Person person1=new Person("22",777);
          Person person2=new Person("33",10);

          List<Person>list=new ArrayList();

          list.add(person);
          list.add(person1);
          list.add(person2);

          objectOutputStream.writeObject(list);

          objectOutputStream.close();
      }


      public  static  void  fxlh() throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("day12\\\\listTest.txt"));
         List<Person>list=new ArrayList();
         list=(ArrayList<Person>)objectInputStream.readObject();

          for (Person person : list) {
              System.out.println(person);
          }
          objectInputStream.close();
      }
}
